package com.bwf.coll;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/23 13:37
 * @Copyright 博为峰
 */
public class ArrayListDemo {
    public static void main(String[] args) {
//        m1();
//        m2();
//        m3();
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new Student("张三", 20));
        arrayList.add(new Student("李四", 30));
//        final Iterator iterator = arrayList.listIterator();//多态
        final ListIterator listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            final Student student = (Student) listIterator.next();
//            arrayList.add(new Student("李四",30));
            listIterator.add(new Student("李四", 30));
            System.out.println(student);
        }
    }

    private static void m3() {
        final ArrayList arrayList = new ArrayList();
        arrayList.add(new Student("张三", 20));//多态 Object o = new Student("张三", 20)
        arrayList.add(new Student("李四", 30));
        final Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            final Student student = (Student) iterator.next();
            arrayList.add(new Student("李四", 30));
            System.out.println(student);
        }
    }

    private static void m2() {
        final ArrayList arrayList = new ArrayList();
        arrayList.add("a");//Object o = "a"
        arrayList.add("b");
        arrayList.add("c");
        arrayList.add("a");
        final Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            final String next = (String) iterator.next();
            System.out.println(next);
        }
    }

    private static void m1() {
        final ArrayList arrayList = new ArrayList();
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        arrayList.add("a");
//        System.out.println(arrayList);
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(arrayList.get(i));
        }
    }
}
